# 调用库
import calendar
from datetime import datetime
import sys

# 输入到文件
class Logger(object):
    def __init__(self, filename='default.log', stream=sys.stdout):
        self.terminal = stream
        self.log = open(filename, 'w')
 
    def write(self, message):
        self.terminal.write(message)
        self.log.write(message)
 
    def flush(self):
        pass
sys.stdout = Logger('a.text', sys.stdout)
sys.stderr = Logger('a.log_file', sys.stderr)

# 获取电脑时间信息并输出当日所在月份的月历
year = calendar.datetime.datetime.now().year
month = calendar.datetime.datetime.now().month
day = calendar.datetime.datetime.now().day
current_calendar = calendar.monthcalendar(year,month)
month_name = calendar.month_name[month]
now = datetime.now()

# 定义年历函数
def almanac (a):
    for i in range(1,12):
        print(calendar.month(a,i))

# 输出当日信息以及当月日历
print("--------------------------")
print("     以下是当日信息\n")
print(now,"\n")
print(f"today is {month_name} {day} {year}","\n")
print(calendar.month(year,month))
print("--------------------------")

# 输出当年的年历
print("以下是当年的万年历")
a = year
almanac(a)
print("--------------------------")

# 输出指定年份的万年历
print("指定年份的万年历")
b = int(input("请输入一个年份："))
print("以下是%d年的年历"%(b))
almanac(b)
print("--------------------------")
